   
    
    $(function() {
    	var userInfo = $.cookie('login_cookie');
        if (userInfo != null && userInfo != "") {
			var name = userInfo.split("%")[1];
			$(".header-left").html(
					"欢迎，"+name+"&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' class='link-logout' onclick='logout()'>[退出]</a>"		
			);
		} else {
			window.location.href = ("login.html");
		}
    	 $.ajax({
	          url:"car/list",
	          type: "GET",
	          success: function(data) {
			if(data!=null){
	            var car=data;
	            for (var i = 0; i < car.length; i++) {
	             $("#table_list").append(
	            		 "<tr><td>"
	            		 + car[i].carid + "</td><td>"
	            		 + car[i].teacher + "</td><td>"
	            		 + car[i].remarks + "</td><td>"
	            		 +"<a href='update-car.html?"+car[i].carid+"') style='cursor:pointer'><i class='fa  fa-pencil'>&nbsp;修改</i></a>&nbsp;&nbsp;&nbsp;&nbsp;" +
	            		 		"<a href='javascript:void(0)' onclick=deleteCar('"+car[i].carid+"') style='cursor:pointer'><i class='fa fa-trash-o'>&nbsp;删除</i></a>"+ "</td></tr>"
	            		 
	            		 );
	        		}
				}
	          }
			});
    	//为注册按钮绑定点击注册时间  出发regist方法
    	$("#stu_search").click(function(){
    		
    		return serach();
    	});
    	
    }) 
     function logout() {
		$.ajax({
			url : "user/logout",
			type : "post",
			dateType : "json",
			success : function(data) {
				window.location.reload();
			},
			error : function(e) {
				alert("请求失败！");
			}
		})
    }
function deleteCar(id){
	$.ajax({
		url:"car/delete?car_id="+id,
		type:"get",
		dataType:"json",
		async:false,
		success:function(data){
			var flag=data.success;
			if(flag){
				alert("删除成功！")
			}else{
				alert("删除失败！")
			}
		}
    })
    }
    
   

    
function serach(){
	var search=$("input[name='stu_search_text']").val();
	$('#table_list').children().empty();
	$.ajax({
		url:"car/search",
		data:{"info":search},
		type:"post",
		dataType:"json",
		async:false,
		success:function(data){
			if(data!=null){
	            var car=data;
	            for (var i = 0; i < car.length; i++) {
	            	 $("#table_list").append(
		            		 "<tr><td>"
		            		 + car[i].carid + "</td><td>"
		            		 + car[i].teacher + "</td><td>"
		            		 + car[i].remarks + "</td><td>"
		            		 +"<a href='update-car.html?"+car[i].carid+"') style='cursor:pointer'><i class='fa  fa-pencil'>&nbsp;修改</i></a>&nbsp;&nbsp;&nbsp;&nbsp;" +
		            		 		"<a href='javascript:void(0)' onclick=deleteCar('"+car[i].carid+"') style='cursor:pointer'><i class='fa fa-trash-o'>&nbsp;删除</i></a>"+ "</td></tr>"
		            		 
		            		 );
	        		}
				}
			}
	})
	}